<?php
header("content-type:text/html;charset=utf8");
$username=$_POST["username"];
$password=$_POST["password"];
$email=$_POST["email"];
$tel=$_POST["phone"];
$conn=mysqli_connect("127.0.0.1","root","root","mysql");
mysqli_query($conn,"set names uft8");
$res=mysqli_query($conn,"select * from `userinfo` where `username`='$username'");
$row=mysqli_fetch_assoc($res);
if($row){
    $arr=[
        "meta"=>[
            "status"=>2,
            "msg"=>"该用户名已被占用"
        ],
        "data"=>null
    ];
}else{
    $res = mysqli_query($conn,"insert `userinfo`(username,password,email,tel) values('$username','$password','$email','$tel')");
    if($res){ // 添加成功
        $arr = [
            "meta"=>[
                "status"=>0,
                "msg"=>"注册成功"
            ],
            "data"=>null
        ];
    }else{
        $arr = [
            "meta"=>[
                "status"=>1,
                "msg"=>"注册失败"
            ],
            "data"=>null
        ];
    }
}
echo json_encode($arr);
?>